package com.ph.finder.client.mapper.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;
import com.ph.finder.client.AddressInfo;

public class AddressResultItem extends Composite {

	private static AddressResultItemUiBinder uiBinder = GWT
			.create(AddressResultItemUiBinder.class);

	interface AddressResultItemUiBinder extends
			UiBinder<Widget, AddressResultItem> {
	}

	@UiField
	InlineHyperlink address;

	@UiField
	InlineLabel voterCount;

	private final PrecinctSelectLPanel ctr;

	private final AddressInfo addressInfo;

	public AddressResultItem(PrecinctSelectLPanel ctr,
			AddressInfo addressInfo,
			String addressStr,
			Long voterCount) {
		this.ctr = ctr;
		this.addressInfo = addressInfo;
		initWidget(uiBinder.createAndBindUi(this));
		this.address.setText(addressStr);
		this.voterCount.setText(NumberFormat.getDecimalFormat().format(voterCount));
	}

	@UiHandler("address")
	void onClick(ClickEvent e) {
		ctr.selectAddress(addressInfo);
	}

}
